package cn.xz.xy.adapter

import android.widget.ImageView
import android.widget.TextView
import cn.xz.xy.R
import cn.xz.xy.bean.LightList
import cn.xz.xy.net.ControlDevice
import cn.xz.xy.widgets.AutoScaleTextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 灯光列表适配器*/
class LightCAdapter: BaseQuickAdapter<LightList, BaseViewHolder>(R.layout.item_light_c){

    override fun convert(holder: BaseViewHolder, item: LightList) {

        val tvLightC = holder.getView<AutoScaleTextView>(R.id.tv_light_c)
        tvLightC.post {
            tvLightC.text = item.name.toString()
        }

        holder.getView<TextView>(R.id.tv_start).setOnClickListener {
            ControlDevice.openLight(item)
            item.opening = true
            notifyItemChanged(holder.adapterPosition)
        }

        holder.getView<TextView>(R.id.tv_stop).setOnClickListener {
            ControlDevice.closeLight(item)
            item.opening = false
            notifyItemChanged(holder.adapterPosition)
        }

        val ivItemImg = holder.getView<ImageView>(R.id.iv_item_img)

        //是否已经开启
        ivItemImg.isSelected = item.opening
    }
}